package com.aidl.demo.ui.activity;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import com.aidl.demo.R;
import com.aidl.demo.mvp.LivePresenter;
import com.aidl.demo.ui.adapter.LiveListAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class LiveActivity extends BaseActivity<LivePresenter> implements LivePresenter.LiveView {

    @BindView(R.id.recycler_live_list)
    RecyclerView mRecyclerLiveList;
    @BindView(R.id.tv_num)
    AppCompatTextView mTvNum;
    @BindView(R.id.re_key_num)
    RelativeLayout mReKeyNum;
    @BindView(R.id.tv_live_name)
    AppCompatTextView mTvLiveName;
    @BindView(R.id.tv_epg_now)
    AppCompatTextView mTvEpgNow;
    @BindView(R.id.tv_epg_next)
    AppCompatTextView mTvEpgNext;
    @BindView(R.id.channel_info)
    RelativeLayout mChannelInfo;
    @BindView(R.id.relativelayout_channel)
    RelativeLayout mRelativelayoutChannel;
    @BindView(R.id.progressBar_loading_video)
    ProgressBar mProgressBarLoadingVideo;

    @Override
    protected int getContentResId() {
        return R.layout.activity_live;
    }

    private LiveListAdapter mLiveListAdapter;
    private LinearLayoutManager mLayoutManager;

    @Override
    protected void initView() {
        //直播节目列表
        mLayoutManager = new LinearLayoutManager(this);
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerLiveList.setLayoutManager(mLayoutManager);
        mLiveListAdapter = new LiveListAdapter(this);
        mRecyclerLiveList.setAdapter(mLiveListAdapter);
        initListener();
    }

    private void initListener() {
        mLiveListAdapter.setOnItemClickListener(new LiveListAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }
        });
        mLiveListAdapter.setOnItemKeyDownListener(new LiveListAdapter.OnItemKeyDownListener() {
            @Override
            public void onItemKeyDown(View view, int position, int oritation) {
                mRecyclerLiveList.scrollToPosition(position);
            }
        });
    }

    @Override
    protected void initData() {
        setPresenter(new LivePresenter(this));
        getPresenter().loadLiveData(this);
        List<MyLiveData> liveData = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            int number = i + 1;
            liveData.add(new MyLiveData(number + "", "CCTV" + number));
        }
        mLiveListAdapter.setData(liveData, 0);
    }

    @Override
    public void loadListSuccess(LivePresenter.Live liveDatas) {

    }

    @Override
    public void loadFailed(int error) {

    }

    public static class MyLiveData {
        private String number;
        private String name;

        public MyLiveData(String number, String name) {
            this.number = number;
            this.name = name;
        }

        public String getNumber() {
            return number;
        }

        public void setNumber(String number) {
            this.number = number;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
